/* TCSS 590A - Cybernetics and Systems
 * Group Project - Modeling
 * By Barry Jones, Naren Meadem, Michael Pitts, Yuan Tao
 * Fall 2012, University of Washington, Tacoma
 */
package model.delayed;


/**
 * This class generates a set value on every call to generate, it is NOT random.
 * @author Michael Pitts
 * @version Nov 16, 2012
 */
public class SimpleGenerator extends EventGenerator
{
	/** The value that is always used in generate().*/
	private final long my_value;
	
	/** The delay that is always used in delay().*/
	private final int my_delay;
	
	private long my_last_value_time = -1;

	/**
	 * Creates a new Simple Generator.
	 * @param the_value is the value returned on every call to generate().
	 * @param the_delay is the delay returned on every call to delay().
	 */
	public SimpleGenerator(final long the_value, final int the_delay)
	{
		my_value = the_value;
		my_delay = the_delay;
	}
	
	/**
	 * Generates a SimpleGenerator with no delay.
	 * @param the_value is the value returned on every call to generate.
	 */
	public SimpleGenerator(final long the_value)
	{
		this(the_value, 0);
	}

	@Override public long generate(final long the_time)
	{
		if (the_time == my_last_value_time) return 0;
		my_last_value_time = the_time;
		return my_value;
	}

	@Override public int delay(final long the_time)
	{
		return my_delay;
	}

}
